<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="author" content="甘忠祥">
    <title>模拟select</title>
    <style>
    
        .box{
            width: 500px;
            height: 800px;
            border: 1px solid black;
            margin: 50px auto;
        }
        .kuang{
            list-style: none;
            display: flex;
            margin-top: 50px;
        }
        .select{
            background-color: lightgreen;
            height: 50px;
            width: 130px;
            line-height: 50px;
            padding-left: 80px;
        }
        .choose{
            background-color: lightgray;
            height: 50px;
            width: 130px;
            line-height: 50px;
            padding-left: 80px;
            cursor: pointer;
        }
        .list{
            list-style: none;
             /* position: relative;  */
             /* left: 210px;  */
             /* margin-top: -15px; */
            /* display: none; */
            position: absolute;
            top: 150px;
            left: 920px;
    
        }
        .list li{
            border: 1px dotted black;
            height: 50px;
            width: 130px;
            line-height: 50px;
            padding-left: 80px;
            cursor: pointer;
        }
        .list li:hover{
            background-color: lightgray;
        }
    </style>
</head>
    
<body>
    <div class="box">
        <ul class="kuang">
            <li class="select">选择项目:</li>
            <li class="choose">未选择</li>
                <ul class="list">
                    <li>html</li>
                    <li>css</li>
                    <li>javascript</li>
                    <li>jQuery</li>
                </ul>
        </ul>
    
    </div>
<script src="./jquery.min.js"></script>
</body>
<script>
    $('.list').css('display','none');

    $('.choose').click(function(ev){
        $('.list').css('display','block');
        ev.stopPropagation();
    });
    // console.log($('.choose').html());
    $('.list>li').click(function(){
    // console.log($(this).html());
        $('.choose').html($(this).html());
        $('.list').css('display','none');
        
        
    });
    $('body').click(function(){
        // console.log(123);
        if($('.list').css('display','block')){
            
            $('.list').css('display','none');
        }
    })

   
</script>
</html>